//
//  ViewController.swift
//  Swift_Learn
//
//  Created by EDY on 5/22/25.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //字符串
        let sun = "\u{2600}"
        let snow = "\u{2744}"
        let sunAndSnow = "\u{2600}\u{2744}"
        let name = ""
        if(name.isEmpty){
            self.view.backgroundColor = UIColor.red
        }else{
            self.view.backgroundColor = UIColor.blue
        }
        let sunAndSnowOther = "下雪 \(snow) 太阳\(sun)"
        
        let sunName = sunAndSnow + name
        if(sunAndSnow == sunName){
            print(sun)
        }
        print(sunAndSnowOther)
        let students = ["Liming","Simon","Jerry"]
        for student in students {
            print(student)
        }
        var myVariable = 43
        myVariable = 20
        print(myVariable)
        //函数
        let hello = greet(person: "LIU YONG HUI")
        print(hello)
        
        //类
        let car = Car(brand: "Toyota", year: 2020)
        car.drive()
        
        //枚举
        let direction = CompassPoint.north
        switch direction {
        case .north:
            print("go north")
        case .south:
            print("go south")
        case .east:
            print("go east")
        default:
            print("other direction")
        }
        
        
        let daysOfWeek:[String] = ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"]
        for day in daysOfWeek {
            print(day)
        }
        
        
        let person = Person(name: "ZSS", age: 30)
        person.greet()
        
        let student = Student(name: "李四", age: 20, studentID: 12345)
         student.greet()
        
        let book = DevBook(title: "编程", author: "LYH")
        book.description()
        
        let namesGM = ["Chris","Alex","Ewa","Barry"]
        let sortedNames = namesGM.sorted {
            (name1: String, name2: String) -> Bool in return name1 < name2
        }
        print(sortedNames)
        
        var number1 = 5
        var number2 = 10
        swapTowValues(&number1, &number2)
        print("number1=\(number1)  number2=\(number2)")
        
        //测试协议
        let personProtocol = Person(name: "ZSSHH", age: 23)
        print(personProtocol.describe())
        
        
        gcd()
        
        
    }
    
    func gcd() {
        DispatchQueue.global().async {
            for i in 1...5 {
                print("异步任务 \(i)")
            }
        }
        
        DispatchQueue.main.async {
            print("更新 UI")
        }
    }
    
    func swapTowValues<T>(_ a: inout T, _ b: inout T) {
        let temporaryA = a
        a = b
        b = temporaryA
    }
    
    func greet(person: String) -> String {
        return "Hello \(person)"
    }
    
    func sayHello() {
        print("Hello")
    }


}

